#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os
import shutil
import e2erlang
import e2json
import e2lua


def files():
	path = "./../excel/"
	fs = []
	for f in os.listdir(path):
		# 排除临时文件
		if f[0] == "~":
			continue
		# 找出 xxxxx_cfg.xlsx 文件
		if "cfg.xlsx" == f.split("_")[-1]:
			fs.append(path + f)
	return fs

def init_output():
	output = "./../output"
	erlang = "./../output/erlang"
	json = "./../output/json"
	lua = "./../output/lua"

	if os.path.exists(erlang):
		shutil.rmtree(erlang)
	if os.path.exists(json):
		shutil.rmtree(json)
	if os.path.exists(lua):
		shutil.rmtree(lua)

	if not os.path.exists(output):
		os.mkdir(output)
	os.mkdir(erlang)
	os.mkdir(json)
	os.mkdir(lua)


def main():
	init_output()
	fs = files()
	print("-- excel files")
	for f in fs:
		print("excel: " + f)
	e2erlang.convert(fs)
	e2json.convert(fs)
	#e2lua.convert(fs)
	print("-- complite")

if __name__ == '__main__':
	print("测试输出")
	print("------------------------------------------------")
	main()


